﻿@using CoreData
@using Helper
@model IList<Search>
@{
    var TitleName = @ViewBag.TitleName;
    ViewBag.Title = "Tìm kiếm cho từ khóa " + '"' + @TitleName + '"';
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{

    Layout = "~/Views/Shared/_Layout.cshtml";   
}
@section HeadResource{
    <title>Tìm kiếm cho từ khóa "@TitleName"</title>
    <link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/css/search.css")">
}
@section BottomResource{
    <script type="text/javascript" src="@Url.Content("~/Content/js/search.js")"></script>
}
@helper pagerHelper()
    {
        int totalPage = ViewBag.TotalPage;
        int currentPage = (int)ViewBag.page;
        int i = 0;    
    <ul>
        <li class="bullet-first"><a href="@Url.Action("Index", "Search", new { value = ViewBag.TitleName })">
            <<</a></li>
        @if (currentPage > 1)
        {
            <li class="bullet-prev"><a href="@Url.Action("Index", "Search", new { value = ViewBag.TitleName, page = currentPage - 1 })">
                Prev</a></li>
        }
        @if (totalPage > 0)
        {
            var startPage = currentPage - 2;
            var endPage = currentPage + 2;
            if (startPage < 1) { startPage = 1; }
            if (endPage > totalPage) { endPage = totalPage; }

            if (currentPage >= 4)
            {
            <li><a href="#">...</a></li>
            }
            for (i = startPage; i <= endPage; i++)
            {
                if (currentPage == i)
                {
            <li class="current-page"><a href="@Url.Action("Index", "Search", new { value = ViewBag.TitleName, page = i })">@i</a></li>
                }
                else
                {
            <li><a href="@Url.Action("Index", "Search", new { value = ViewBag.TitleName, page = i })">@i</a></li>
                }
            }
            if (currentPage <= totalPage - 2)
            {
            <li><a href="#">...</a></li>
            }
        }
        @if (currentPage < totalPage)
        {
            <li class="bullet-next"><a href="@Url.Action("Index", "Search", new { value = ViewBag.TitleName, page = currentPage + 1 })">
                Next</a></li>
        }
        <li class="bullet-last"><a href="@Url.Action("Index", "Search", new { value = ViewBag.TitleName, page = totalPage })">
            >></a></li>
    </ul>
}
@if (Model != null && Model.Count() > 0)
{
    <div class="grid-view search-grid">
        <div class="grid-title">
            <h3>
                Kết quả @ViewBag.Title (@ViewBag.CountItem)</h3>
        </div>
        <ul class="row-search">
            @foreach (var item in Model)
            {
                <li class="row-item">
                    <div class="row-inner">
                        <div class="product-thumbnail">
                            <a href="@item.Link" title="@item.Name">
                                <img src="/Media/Product/@item.Image" alt="@item.Image" />
                            </a>
                        </div>
                        <div class="row-details">
                            @{
                var productname = item.Name;
                var Description = item.Description;
                if (productname.Length > 100)
                {
                    productname = productname.Substring(0, 100) + "...";
                }
                if (Description.Length > 150) {
                    Description = Description.Substring(0, 150) + "...";
                }
                                <h1 class="search-title">
                                    <a href="@item.Link" title="@item.Name">@productname</a></h1>
                                <p class="search-description">@Description</p>
                            }
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </li>
            }
        </ul>
        <div class="clearfix">
        </div>
        <div class="grid-title">
            <div class="link-to-all paging">
                @pagerHelper()
            </div>
        </div>
        <div class="clearfix">
        </div>
    </div>
}